
public class ThreadPoolTest {
	
	public static void main(String[] args) 
	{
			if (args.length!=2)
			{
				System.out.println("Tests the ThreadPool task.");
				System.out.println("Java ThreadPoolTest numTasks numThreads");
				System.out.println("numTasks: integer num of tasks to run");
				System.out.println("numThreads: integer num of threads in the pool.");
				return;
			}

				int numTasks = Integer.parseInt(args[0]);
				int numThreads = Integer.parseInt(args[1]);

				//int numTasks = 4;
				//int numThreads = 3;

			
			//create pool
			ThreadPool threadPool = new ThreadPool(numThreads);
			//run example tasks
			
			for (int i =0; i<numTasks;i++)
			{
				threadPool.runTask(createTask(i));
			}
			
			//cloose the pool and wait fot the task to finish
			threadPool.join();
			
		}
	
	/**
	 * Creates a simple runnable that prints the ID waits 500ms and prints ID again
	 */
	
private static Runnable createTask( final int taskID)
{ 
	return new Runnable()
	{
		public void run()
		{
			System.out.println("Task "+ taskID + " start");
			
			//simulate a long running task
			try{
				Thread.sleep(500);
			}
			catch(InterruptedException ex){}
			
			System.out.println("Task "+ taskID + " end");
		}
		
	};

}
}